package com.jzr.bedside.presenter.impl

import android.content.Context
import com.jzr.bedside.api.Api
import com.jzr.bedside.base.BasePresenter
import com.jzr.bedside.bean.BedInfoBean
import com.jzr.bedside.bean.FeeRecordListBean
import com.jzr.bedside.bean.TestReportListBean
import com.jzr.bedside.presenter.contract.TestActivityContract
import rx.Observer
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers

class TestActivityImpl : BasePresenter<TestActivityContract.View>(),
    TestActivityContract.Presenter<TestActivityContract.View>{



    override fun getTestReportList(context: Context?, vararg query: String?) {
        showLoadingDialog(context)
        addSubscrebe(
            Api.getInstance()?.getTestReportList(*query)
                ?.observeOn(AndroidSchedulers.mainThread())
                ?.subscribeOn(Schedulers.io())
                ?.unsubscribeOn(Schedulers.io())
                ?.subscribe(object : Observer<TestReportListBean?> {
                    override fun onCompleted() {}
                    override fun onError(e: Throwable) {
                        dismissLoadingDialog()
                        if (mView != null) mView?.showError("连接失败")
                    }

                    override fun onNext(t: TestReportListBean?) {
                        dismissLoadingDialog()
                        if (mView != null && t != null && t.code ==0 && t.data!=null) {
                            mView?.getTestReportListSuccess(t)
                        } else {
                            mView?.showError(t?.message)
                        }
                    }
                })
        )
    }


}